package com.passioneffect.widgets {
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.utils.getDefinitionByName;		

	/**
	 * @author Passion Effect
	 */
	public class DiaganolLine {
		public var target:DisplayObject;
		public var pattern: String;
		private var mc : Sprite;

		public function DiaganolLine(t:DisplayObject,pattern:String){
			this.pattern=pattern;
			target=t;
		}
		
		public function getPattern():BitmapData{
			var def=getDefinitionByName(pattern);
			var mc:MovieClip=new def();
			var bitmapData:BitmapData=new BitmapData(mc.width,mc.height,true,0xffffff00);
			bitmapData.draw(mc);
			return bitmapData;
		}
		
		public function open():void{
			var rect:Rectangle=target.getRect(target.parent);
			var p:BitmapData=getPattern();
			var mc:Sprite=new Sprite();
			var g:Graphics=mc.graphics;
			g.lineStyle();
			g.beginBitmapFill(p);
			g.drawRect(rect.x+10, rect.y, rect.width,rect.height);
			g.endFill();
			target.parent.addChild(mc);
			this.mc=mc;
		}
		
		public function close():void{
			if(target.parent.contains(mc)){
				target.parent.removeChild(mc);
			}
		}
		
		public function getDiagonal():DisplayObject{
			return mc;
		}
	}
}
